package com.ruoyi.fpa.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fpa.domain.FpaAttachment;
import com.ruoyi.fpa.service.IFpaAttachmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 附件Controller
 * 
 * @author koradji@116.com
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/fpa/attachment")
public class FpaAttachmentController extends BaseController
{
    @Autowired
    private IFpaAttachmentService fpaAttachmentService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('fpa:attachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(FpaAttachment fpaAttachment)
    {
        startPage();
        List<FpaAttachment> list = fpaAttachmentService.selectFpaAttachmentList(fpaAttachment);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('fpa:attachment:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FpaAttachment fpaAttachment)
    {
        List<FpaAttachment> list = fpaAttachmentService.selectFpaAttachmentList(fpaAttachment);
        ExcelUtil<FpaAttachment> util = new ExcelUtil<FpaAttachment>(FpaAttachment.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('fpa:attachment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(fpaAttachmentService.selectFpaAttachmentById(id));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('fpa:attachment:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FpaAttachment fpaAttachment)
    {
        return toAjax(fpaAttachmentService.insertFpaAttachment(fpaAttachment));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('fpa:attachment:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FpaAttachment fpaAttachment)
    {
        return toAjax(fpaAttachmentService.updateFpaAttachment(fpaAttachment));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('fpa:attachment:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(fpaAttachmentService.deleteFpaAttachmentByIds(ids));
    }
}
